import 'package:flutter/material.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/entities/deliver_goods_entity.dart';
import 'package:library_base/entities/enum_entity.dart';
import 'package:library_base/entities/stock_out_child_entity.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/res/colors.dart';
import 'package:library_base/res/decoration.dart';
import 'package:library_base/res/dividing_line.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/res/widget_generator.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/res/edge.dart';
import 'package:get/get.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:library_base/widget/button/ink_bg_well.dart';
import 'package:library_base/widget/image/local_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:module_wms/page/deliver_goods/deliver_goods_controller.dart';

Widget buildSearchWidget(
  DeliverGoodsController asOrderController, {
  ValueChanged<String>? onChanged,
  ValueChanged<String>? onSearch,
}) {
  return Container(
    color: ThemeUtil.getTheme().colorScheme.secondary,
    height: 116.w,
    child: Row(
      children: <Widget>[
        Expanded(
          child: Container(
              alignment: Alignment.center,
              height: double.infinity,
              width: double.infinity,
              margin: EdgeInsets.only(left: 24.w, top: 24.w, bottom: 24.w),
              decoration: BoxDecoration(
                color: ThemeUtil.getTheme().secondaryBgColor(),
                borderRadius: const BorderRadius.all(Radius.circular(30.0)),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  gapW24,
                  LocalImage('common_search',
                      package: Constant.packLib(), width: 26.w, height: 26.w),
                  gapW24,
                  Expanded(
                    child: Container(
                      alignment: Alignment.center,
                      height: double.infinity,
                      width: double.infinity,
                      child: TextField(
                        onChanged: onChanged,
                        autofocus: false,
                        style: normalTextColor28,
                        controller: asOrderController.keyWorkSearchController,
                        textAlignVertical: TextAlignVertical.center,
                        decoration: InputDecoration(
                          focusedBorder: const OutlineInputBorder(
                              borderSide: BorderSide(
                                  width: 0, color: Colors.transparent)),
                          disabledBorder: const OutlineInputBorder(
                              borderSide: BorderSide(
                                  width: 0, color: Colors.transparent)),
                          enabledBorder: const OutlineInputBorder(
                              borderSide: BorderSide(
                                  width: 0, color: Colors.transparent)),
                          contentPadding:
                              const EdgeInsets.symmetric(vertical: 0),
                          border: InputBorder.none,
                          labelStyle: TextStyles.textNormal28,
                          hintText: MultiLanguage.pleaseEnterNumber.tr,
                          hintStyle: TextStyles.textSixthColor28,
                          suffixIcon: asOrderController.keyWord.isNotEmpty
                              ? IconButton(
                                  iconSize: 30.w,
                                  icon: Icon(Icons.close,
                                      color: Colours.gray_400, size: 40.w),
                                  onPressed: () {
                                    asOrderController
                                        .keyWorkSearchController.text = '';
                                    asOrderController.keyWord.value = "";
                                    asOrderController.update();
                                  },
                                )
                              : gapZero,
                        ),
                      ),
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.only(right: 24.w),
                    child: LocalImage('wms_scan',
                        package: Constant.packWms(), width: 32.w, height: 32.w),
                  ),
                ],
              )),
        ),
        textInkBgWell(MultiLanguage.search.tr, onTap: (action) {
          onSearch?.call(action);
        })
      ],
    ),
  );
}

Widget buildBottom(
  double finishedCount,
  double totalCount,
  bool enable,
  bool isSelectedAll,
  int selectCount, {
  void Function()? print,
  void Function()? deliverGoods,
}) {
  return Container(
    color: Colors.white,
    child: Column(
      children: [
        Container(
            height: 166.w,
            decoration: rectTop,
            alignment: Alignment.topRight,
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(
                  child: GradientButton(
                    ThemeUtil.getTheme(),
                    decoration: BoxDecoration(
                        borderRadius:
                            const BorderRadius.all(Radius.circular(20)),
                        border: Border.fromBorderSide(BorderSide(
                            color: ThemeUtil.getTheme().sixthTextColor())),
                        color: ThemeUtil.getTheme().colorScheme.secondary),
                    normalColor: ThemeUtil.getTheme().colorScheme.secondary,
                    textStyle:
                        enable ? normalTextColor28 : secondaryTextColor28,
                    height: 77.w,
                    margin: EdgeInsets.only(right: 16.w, top: 21.w),
                    padding: EdgeInsets.symmetric(horizontal: 30.w),
                    text: MultiLanguage.print.tr,
                    onPressed: enable ? print : null,
                  ),
                ),
                Expanded(
                  child: GradientButton(
                    ThemeUtil.getTheme(),
                    decoration: BoxDecoration(
                        borderRadius:
                            const BorderRadius.all(Radius.circular(20)),
                        border: Border.fromBorderSide(BorderSide(
                            color: ThemeUtil.getTheme().sixthTextColor())),
                        color: ThemeUtil.getTheme().colorScheme.secondary),
                    normalColor: ThemeUtil.getTheme().colorScheme.secondary,
                    textStyle:
                        enable ? normalTextColor28 : secondaryTextColor28,
                    height: 77.w,
                    margin: EdgeInsets.only(right: 16.w, top: 21.w),
                    padding: EdgeInsets.symmetric(horizontal: 30.w),
                    text: MultiLanguage.print.tr,
                    onPressed: enable ? print : null,
                  ),
                ),
                Expanded(
                  child: GradientButton(
                    ThemeUtil.getTheme(),
                    height: 77.w,
                    margin: EdgeInsets.only(right: 24.w, top: 21.w),
                    padding: EdgeInsets.symmetric(horizontal: 30.w),
                    text: MultiLanguage.sendOut.tr,
                    onPressed: enable ? deliverGoods : null,
                  ),
                ),
              ],
            )),
      ],
    ),
  );
}

Widget buildItem(
  DeliverGoodsEntity taskEntity,
  int position, {
  Function(DeliverGoodsEntity taskEntity, int position)? toOrderDetail,
}) {
  List<Widget> widgets = [];

  ///第一行内容
  widgets.add(Container(
    color: Colors.transparent,
    padding: edgeAll24,
    child: Row(
      children: [
        Padding(
            padding: EdgeInsets.only(left: 10.w),
            child: Text("MWXS20221117002", style: normalTextColor28)),
      ],
    ),
  ));
  widgets.add(line1);
  var infoWidget = Padding(
    padding: edgeLR24,
    child: Row(children: [
      Expanded(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            gapH18,
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("${MultiLanguage.productName.tr} : ", style: normalTextColor28),
                Expanded(
                    child: Text("", style: normalTextColor28)),
              ],
            ),
            gapH18,
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(
                  child: Row(children: [
                    Text("${MultiLanguage.productBatch.tr} : ",
                        style: normalTextColor28),
                    Expanded(
                        child:
                        Text('', style: normalTextColor28)),
                  ]),
                ),
                Expanded(
                  child: Row(children: [
                    Text("${MultiLanguage.seat.tr} : ",
                        style: normalTextColor28),
                    Expanded(
                        child:
                        Text('', style: normalTextColor28)),
                  ]),
                ),
              ],
            ),
            gapH18,
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("${MultiLanguage.tareDeduction.tr}(KG) : ", style: normalTextColor28),
                Expanded(
                    child: Text("", style: normalTextColor28)),
              ],
            ),
            gapH18,
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(
                  child: Row(children: [
                    Text("${MultiLanguage.peelMainWeight.tr}(KG) : ",
                        style: normalTextColor28),
                    Expanded(
                        child:
                        Text('', style: normalTextColor28)),
                  ]),
                ),
                Expanded(
                  child: Row(children: [
                    Text("${MultiLanguage.auxiliaryWeight1.tr}(KG) : ",
                        style: normalTextColor28),
                    Expanded(
                        child:
                        Text('', style: normalTextColor28)),
                  ]),
                ),
              ],
            ),
            gapH18,
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("${MultiLanguage.shortName.tr} : ", style: normalTextColor28),
                Expanded(
                    child: Text("", style: normalTextColor28)),
              ],
            ),
          ],
        ),
      ),
    ]),
  );
  widgets.add(infoWidget);
  widgets.add(gapH24);
  return GestureDetector(
    onTap: () {
      toOrderDetail?.call(taskEntity, position);
    },
    child: roundWidget(
      margin: edgeLR24,
      decoration: rs8,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: widgets,
      ),
    ),
  );
}

String getStatusName(DeliverGoodsEntity taskEntity) {
  // if (taskEntity.status == StockOutOrderStatus.NOT_ASSIGN.name) {
  //   return Messages.undistributed.tr;
  // } else if (taskEntity.status == StockOutOrderStatus.ASSIGNED.name) {
  //   return Messages.allocated.tr;
  // } else {
  //   return Messages.weighed.tr;
  // }
  return MultiLanguage.weighed.tr;

}

TextStyle getStatusTextStyle(DeliverGoodsEntity taskEntity) {
  // if (taskEntity.status == StockOutOrderStatus.ASSIGNED.name) {
  //   return fourthTextColor28;
  // } else if (taskEntity.status == StockOutOrderStatus.ASSIGNED.name) {
  //   return primaryTextColor28;
  // } else {
  //   return normalTextColor28;
  // }
  return normalTextColor28;

}

Widget filterWell({
  Function? onTap,
}) {
  return inkBgWell(
    child: Container(
        padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 24.w),
        child: LocalImage('admin_filter',
            package: Constant.packAdmin(), width: 38.w, height: 38.w)),
    onTap: () => onTap?.call(),
    splashColor: ThemeUtil.getTheme().colorScheme.primary.withOpacity(0.5),
  );
}
